config = {
    'host': '127.0.0.1',
    'user': 'root',
    'password': 'Cfy123456',
    'port': 3306,
    'db': 'my_db',
    'charset': 'utf8mb4',
}

from constant import config
from mysql import *
from TemperatureCreate import *


def insertTemp():
    mydb = Mysql(config)
    sql = "insert into tb_temp values(%s, %s)"
    tdata = timeCreat()
    ttemp = randomTemperature(20, 30)
    param = getParam(tdata, ttemp)
    mydb.insert(sql, param)


def covertJosn(res):
    res = json.dumps(res, ensure_ascii=False,\
                     sort_keys=True, indent=8)
    return '{\n\t"count"：' + str(days) + \
			'\n\t"result"：' + res[0:len(res) \
                                  - 1] + "\t]\n}"


if __name__ == '__main__':
    # insertTemp() # 先插入一遍
    mydb = Mysql(config)
    sql = "select * from tb_temp"
    strs = covertJosn(mydb.query_all(sql))
    print(strs)